"use strict";
$(function () {
    // player 选择的选项
    let playerChecked;
    gameOptionFn();
    // 游戏选择区域点击事件
    function gameOptionFn() {
        $(".hand-box").find("div").click((e) => {
            playerChecked = $(e.target).text();
            renderPlayer(playerChecked);
        });
    }
    // 给 player 区域赋值
    function renderPlayer(platerText) {
        $(".player").text(platerText);
        renderAi();
    }
    // AI 区域
    function renderAi() {
        let timerNum = 4;
        let timer;
        timer = setInterval(() => {
            timerNum = timerNum - 1;
            $(".aI").text(timerNum);
            if (timerNum === 1) {
                clearInterval(timer);
                // 为 1 后显示 ai 选择结果
                aiSelect();
            }
        }, 1000);
    }
    // AI 选择逻辑
    function aiSelect() {
        /*
            1.生成 随机数 （1 - 3）
            2.根据索引去匹配 ai 的 石头剪刀布
            3.根据 ai 的石头剪刀布 匹配 ai 的石头剪刀布
        */
        let random = Math.floor(Math.random() * 3) + 1;
        let aiChecked;
        if (random === 3) {
            // 布
            aiChecked = "布";
        }
        else if (random === 2) {
            // 剪刀
            aiChecked = "剪刀";
        }
        else {
            // 石头
            aiChecked = "石头";
        }
        $(".aI").text(aiChecked);
        playerResultAi(aiChecked);
    }
    // player ai result 比较逻辑
    function playerResultAi(aiChecked) {
        let result;
        if (playerChecked === aiChecked) {
            result = "猜拳结果相同";
        }
        else if (playerChecked === "石头" && aiChecked === "剪刀" || playerChecked === "剪刀" && aiChecked === "布" || playerChecked === "布" && aiChecked === "石头") {
            result = "您胜利了";
        }
        else {
            result = "很遗憾，您输了";
        }
        $(".reasult-box").text(result);
    }
});
